from django.contrib import admin

from .models import BookInfo, HreoInfo, Account,Contact,Host,Application,Student


# Register your models here.

class HeroInfoInline(admin.StackedInline):
    model = HreoInfo
    # 关联个数
    extra = 1


class BookInfoAdmin(admin.ModelAdmin):
    # 添加自定义显示的字段
    list_display = ['id', 'title', 'pub_date']
    # 添加过滤器
    list_filter = ['title']
    # 模糊查询
    search_fields = ['title']
    # 分页
    list_per_page = 2
    # 添加排序
    ordering = ['id']
    # 再添加书的时候可以额外添加英雄
    inlines = [HeroInfoInline]


class HreoInfoAdmin(admin.ModelAdmin):
    # 添加自定义显示的字段
    list_display = ['id', 'name', 'gender', 'content', 'book', 'skill']
    # 添加过滤器
    list_filter = ['name']
    # 模糊查询
    search_fields = ['name']
    # 分页
    list_per_page = 2
    # 添加排序
    ordering = ['id']


# 注册自己的模型类
admin.site.register(BookInfo, BookInfoAdmin)
admin.site.register(HreoInfo, HreoInfoAdmin)
admin.site.register(Account)
admin.site.register(Contact)
admin.site.register(Host)
admin.site.register(Application)
admin.site.register(Student)
